package bb.lanxing.lib.devices.antplus;

import android.content.Context;
import com.dsi.ant.plugins.antplus.pcc.AntPlusBikeCadencePcc;
import com.dsi.ant.plugins.antplus.pcc.defines.EventFlag;
import com.dsi.ant.plugins.antplus.pccbase.AntPluginPcc;
import com.dsi.ant.plugins.antplus.pccbase.PccReleaseHandle;
import bb.lanxing.lib.devices.api.SmartDevice;
import bb.lanxing.lib.devices.core.provider.DataNotifier;
import java.math.BigDecimal;
import java.util.EnumSet;

public class AntPlusCadence extends AbsAntPlusDevice<AntPlusBikeCadencePcc>
        implements AntPlusBikeCadencePcc.IRawCadenceDataReceiver, AntPlusBikeCadencePcc.ICalculatedCadenceReceiver {
    @Override
    public String getCurrentFileNameInTransfer() {
        return "";
    }

    @Override
    public void onNewRawCadenceData(long j, EnumSet<EventFlag> enumSet, BigDecimal bigDecimal, long j2) {
    }

    public AntPlusCadence(Context context, SmartDevice smartDevice) {
        super(context, smartDevice);
    }

    @Override
    protected PccReleaseHandle<AntPlusBikeCadencePcc> requestAccessToPPC() {
        return AntPlusBikeCadencePcc
                .requestAccess(this.mAppContext, getDeviceNumber(), 0, false, (AntPluginPcc.IPluginAccessResultReceiver<AntPlusBikeCadencePcc>) this, (AntPluginPcc.IDeviceStateChangeReceiver) this);
    }

    @Override
    protected void subscribeEvents(AntPlusBikeCadencePcc antPlusBikeCadencePcc) {
        antPlusBikeCadencePcc.subscribeRawCadenceDataEvent(this);
        antPlusBikeCadencePcc.subscribeCalculatedCadenceEvent(this);
    }

    @Override
    protected void unsubscribeEvents(AntPlusBikeCadencePcc antPlusBikeCadencePcc) {
        if (antPlusBikeCadencePcc != null) {
            antPlusBikeCadencePcc.subscribeRawCadenceDataEvent(null);
            antPlusBikeCadencePcc.subscribeCalculatedCadenceEvent(null);
        }
    }

    @Override
    public void onNewCalculatedCadence(long j, EnumSet<EventFlag> enumSet, BigDecimal bigDecimal) {
        d("calculatedCadence: " + bigDecimal.intValue());
        DataNotifier.notifyCalculatedCadenceData(getType(), bigDecimal.intValue());
        AntPlusDataDispatcher.getInstance().notifyCadenceData(bigDecimal.intValue(), -1);
    }
}
